package com.hiultra.archive.controller;

import com.hiultra.archive.domain.ArcBorrow;
import com.hiultra.archive.domain.ArcBorrowReturn;
import com.hiultra.archive.service.IArcBorrowService;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.core.page.TableDataInfo;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 借阅Controller
 * 
 * @author ls
 * @date 2022-07-28
 */
@Api(tags="借阅管理Controller")
@RestController
@RequestMapping("/borrow/borrow")
public class ArcBorrowController extends BaseController
{
    @Autowired
    private IArcBorrowService arcBorrowService;

    /**
     * 查询借阅列表
     */
    @ApiOperation(value = "查询借阅列表", notes = "查询借阅列表")
    @PreAuthorize("@ss.hasPermi('borrow:borrow:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArcBorrow arcBorrow)
    {
        startPage();
        List<ArcBorrow> list = arcBorrowService.selectArcBorrowList(arcBorrow);
        return getDataTable(list);
    }

    /**
     * 导出借阅列表
     */
    @ApiOperation(value = "导出借阅列表", notes = "导出借阅列表")
    @PreAuthorize("@ss.hasPermi('borrow:borrow:export')")
    @Log(title = "借阅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArcBorrow arcBorrow)
    {
        List<ArcBorrow> list = arcBorrowService.selectArcBorrowList(arcBorrow);
        ExcelUtil<ArcBorrow> util = new ExcelUtil<ArcBorrow>(ArcBorrow.class);
        util.exportExcel(response, list, "借阅数据");
    }

    /**
     * 获取借阅详细信息
     */
    @ApiOperation(value = "获取借阅详细信息", notes = "获取借阅详细信息")
    @PreAuthorize("@ss.hasPermi('borrow:borrow:query')")
    @GetMapping(value = "/{borrowId}")
    public AjaxResult getInfo(@PathVariable("borrowId") Long borrowId)
    {
        return AjaxResult.success(arcBorrowService.selectArcBorrowByBorrowId(borrowId));
    }

    /**
     * 新增借阅
     */
    @ApiOperation(value = "新增借阅", notes = "新增借阅")
    @PreAuthorize("@ss.hasPermi('borrow:borrow:add')")
    @Log(title = "借阅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArcBorrow arcBorrow)
    {
        return toAjax(arcBorrowService.insertArcBorrow(arcBorrow));
    }

    /**
     * 修改借阅
     */
    @ApiOperation(value = "修改借阅", notes = "修改借阅")
    @PreAuthorize("@ss.hasPermi('borrow:borrow:edit')")
    @Log(title = "借阅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArcBorrow arcBorrow)
    {
        return toAjax(arcBorrowService.updateArcBorrow(arcBorrow));
    }

    /**
     * 删除借阅
     */
    @ApiOperation(value = "删除借阅", notes = "删除借阅")
    @PreAuthorize("@ss.hasPermi('borrow:borrow:remove')")
    @Log(title = "借阅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{borrowIds}")
    public AjaxResult remove(@PathVariable Long[] borrowIds)
    {
        return toAjax(arcBorrowService.deleteArcBorrowByBorrowIds(borrowIds));
    }

    /**
     * 借阅归还
     */
    @ApiOperation(value = "借阅归还", notes = "借阅归还")
    @PreAuthorize("@ss.hasPermi('borrow:details:return')")
    @Log(title = "借阅归还",businessType = BusinessType.UPDATE)
    @PutMapping("/return")
    public AjaxResult arcReturn(@RequestBody ArcBorrowReturn arcBorrowReturn){
        return toAjax(arcBorrowService.returnArcBorrowByDetailIds(arcBorrowReturn));
    }
}
